﻿<Window x:Class="ExchangeHog.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
		xmlns:src="clr-namespace:ExchangeHog"
		DataContext="{Binding RelativeSource={RelativeSource Self}}"
        Title="{Binding Config.Title}" Height="350" Width="525" MinWidth="520" MinHeight="350">
	<Window.CommandBindings>
		<CommandBinding Command="ApplicationCommands.Open" Executed="OpenCommandBinding_Executed" CanExecute="OpenCommandBinding_CanExecute"/>
		<CommandBinding Command="ApplicationCommands.Save" Executed="SaveCommandBinding_Executed" CanExecute="SaveCommandBinding_CanExecute"/>
		<CommandBinding Command="ApplicationCommands.SaveAs" Executed="SaveAsCommandBinding_Executed" CanExecute="SaveAsCommandBinding_CanExecute"/>
	</Window.CommandBindings>
	<Window.InputBindings>
		<KeyBinding Command="ApplicationCommands.Open" Key="O" Modifiers="Control" />
		<KeyBinding Command="ApplicationCommands.Save" Key="S" Modifiers="Control" />
		<MouseBinding Command="ApplicationCommands.Open" Gesture="MiddleClick" />
	</Window.InputBindings>
	<Window.Resources>
		<src:BoolToVisibilityConverter x:Key="converterBoolToVisibility"/>
		
		<Style TargetType="{x:Type FrameworkElement}" x:Key="GridBlockStyle">
			<Setter Property="VerticalAlignment" Value="Center" />
			<Setter 
				Property="Visibility" 
				Value="{Binding 
					Path=IsSelected, 
					RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}},
					Converter={StaticResource converterBoolToVisibility},
					ConverterParameter=False}" />
		</Style>
		<Style TargetType="{x:Type FrameworkElement}" x:Key="GridEditStyle">
			<Setter Property="VerticalAlignment" Value="Center" />
			<Setter
				Property="Visibility"
				Value="{Binding 
					Path=IsSelected,
					RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}},
					Converter={StaticResource converterBoolToVisibility},
					ConverterParameter=True}" />
		</Style>
	</Window.Resources>
	<Grid>
		<Label Content="Exchange Server:" Height="30" Margin="16,33,385,0" Name="label1" VerticalAlignment="Top" />
		<TextBox Height="23" Margin="120,35,93,0" Name="tbExchangeServer" VerticalAlignment="Top" Text="{Binding Config.ExchangeUrl}"/>
		<Label Content="Userid:" Height="28" Margin="72,61,385,0" Name="label2" VerticalAlignment="Top" />
		<TextBox Height="23" Margin="120,63,0,0" Name="tbExchangeUserid" VerticalAlignment="Top" HorizontalAlignment="Left" Width="111">
			<TextBox.Text>
				<Binding Path="Config.ExchangeUserid"/>
			</TextBox.Text>
		</TextBox>
		<Label Content="Password:" Height="28" Margin="237,61,203,0" Name="label3" VerticalAlignment="Top" />
		<PasswordBox
			Height="23" Margin="307,63,93,0" Name="pbExchangePassword" VerticalAlignment="Top"
			src:PasswordHelper.Attach="True" 
			src:PasswordHelper.Password="{Binding Config.ExchangePassword, Mode=TwoWay}" 
		/>
		<Button Content="_Go" Height="23" Margin="0,48,12,0" Name="btnGo" VerticalAlignment="Top" HorizontalAlignment="Right" Width="75" Click="btnGo_Click" />
		<GroupBox Header="POP feeders" Margin="16,96,12,12" Name="groupBox1">
			<Grid Name="grid1">
				<ListView HorizontalContentAlignment="Stretch" ItemsSource="{Binding Config.Pop3s}" Name="lvFeeders" VerticalContentAlignment="Stretch" DataContext="{Binding}" Margin="0,0,0,35">
					<ListView.View>
						<GridView>
							<GridViewColumn Width="140">
								<GridViewColumnHeader Content="Server" Tag="Server" />
								<GridViewColumn.CellTemplate>
									<DataTemplate>
										<Grid>
											<TextBlock Text="{Binding Path=Server}" Style="{StaticResource GridBlockStyle}"/>
											<TextBox Text="{Binding Path=Server}" Style="{StaticResource GridEditStyle}" />
										</Grid>
									</DataTemplate>
								</GridViewColumn.CellTemplate>
							</GridViewColumn>
							<GridViewColumn Width="80">
								<GridViewColumnHeader Content="Port" Tag="Port" />
								<GridViewColumn.CellTemplate>
									<DataTemplate>
										<Grid>
											<TextBlock Text="{Binding Path=Port}" Style="{StaticResource GridBlockStyle}"/>
											<TextBox Text="{Binding Path=Port}" Style="{StaticResource GridEditStyle}" />
										</Grid>
									</DataTemplate>
								</GridViewColumn.CellTemplate>
							</GridViewColumn>
							<GridViewColumn Width="80">
								<GridViewColumnHeader Content="SSL" Tag="SSL" />
								<GridViewColumn.CellTemplate>
									<DataTemplate>
										<Grid>
											<CheckBox IsChecked="{Binding Path=SSL}" IsEnabled="False" Style="{StaticResource GridBlockStyle}" />
<!--											<TextBlock Text="{Binding Path=SSL}" Style="{StaticResource GridBlockStyle}"/> -->
											<CheckBox IsChecked="{Binding Path=SSL}" Style="{StaticResource GridEditStyle}" />
										</Grid>
									</DataTemplate>
								</GridViewColumn.CellTemplate>
							</GridViewColumn>
							<GridViewColumn Width="80">
								<GridViewColumnHeader Content="Userid" Tag="Userid" />
								<GridViewColumn.CellTemplate>
									<DataTemplate>
										<Grid>
											<TextBlock Text="{Binding Path=Userid}" Style="{StaticResource GridBlockStyle}"/>
											<TextBox Text="{Binding Path=Userid}" Style="{StaticResource GridEditStyle}" />
										</Grid>
									</DataTemplate>
								</GridViewColumn.CellTemplate>
							</GridViewColumn>
							<GridViewColumn Width="80"> <!-- DisplayMemberBinding="{Binding Password}" -->
								<GridViewColumnHeader Content="Password" Tag="Password" />
								<GridViewColumn.CellTemplate>
									<DataTemplate>
										<Grid>
											<TextBlock Text="***" Style="{StaticResource GridBlockStyle}"/>
											<PasswordBox
												src:PasswordHelper.Attach="True" 
												src:PasswordHelper.Password="{Binding Path=Password, Mode=TwoWay}"
												Style="{StaticResource GridEditStyle}"/>
										</Grid>
									</DataTemplate>
								</GridViewColumn.CellTemplate>
							</GridViewColumn>
						</GridView>
					</ListView.View>
					<ListView.ContextMenu>
						<ContextMenu>
							<MenuItem Command="Delete" IsEnabled="True" />
						</ContextMenu>
					</ListView.ContextMenu>
					<ListView.CommandBindings>
						<CommandBinding Command="ApplicationCommands.Delete" Executed="PopItemDeleteCommandBinding_Executed" CanExecute="PopItemDeleteCommandBinding_CanExecute"/>
					</ListView.CommandBindings>
				</ListView>
				<Button Content="Add New" Margin="0,0,6,6" Name="btnAddNew" Click="btnAddNew_Click" Height="23" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="75" />
			</Grid>
		</GroupBox>
		<Menu Height="23" Name="menuMain" VerticalAlignment="Top">
			<MenuItem Header="_File">
				<MenuItem Command="ApplicationCommands.Open" Header="_Open..." Name="miOpen" />
				<MenuItem Command="ApplicationCommands.Save" Header="_Save" Name="miSave"/>
				<MenuItem Command="ApplicationCommands.SaveAs" Header="Save _As..." Name="miSaveAs" />
			</MenuItem>
			<MenuItem Header="_About" Click="MenuItem_Click" InputGestureText="Alt+A"/>
		</Menu>
	</Grid>
</Window>
